﻿namespace SmartSoft.DAL
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using NLog;

    public class SSInvoiceLibDataAccess
    {
        private static Logger log = LogManager.GetCurrentClassLogger();
        public string CtVAT_So_Ct0_List(object ps_MasterKey)
        {
            string str;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_So_Ct_List", null) };
            values[1].Direction = ParameterDirection.Output;
            values[1].SqlDbType = SqlDbType.NVarChar;
            values[1].Size = 0xfe;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtVAT_So_Ct0_List_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                str = (string)values[1].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return str;
        }

        public int CtVAT_Status_Get(object ps_Ma_Nvu, object ps_MasterKey)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Modul", ps_Ma_Nvu), new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Status", null) };
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.Int;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtVAT_Status_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                num = (int) values[2].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return num;
        }

        public bool DeletePayment(SqlConnection po_Connection, SqlTransaction po_Transaction, object ps_InvoiceOrder, object ps_Ma_Bp, object ps_Ma_Hd, object ps_Ma_Dt, object ps_No_Co, object ps_Tk, object ps_Ma_Tte, object pd_Han_Tt)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Ma_Bp", ps_Ma_Bp), new SqlParameter("p_Ma_Hd", ps_Ma_Hd), new SqlParameter("p_Ma_Dt", ps_Ma_Dt), new SqlParameter("p_No_Co", ps_No_Co), new SqlParameter("p_Tk", ps_Tk), new SqlParameter("p_Ma_Tte", ps_Ma_Tte), new SqlParameter("p_Han_Tt", pd_Han_Tt) };
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "SoCaiTt_Detail_Delete";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                flag = true;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }            
            return flag;
        }

        public decimal ExchangeRate(object ps_Ma_Tte)
        {
            decimal num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Tte", ps_Ma_Tte), new SqlParameter("p_Loai_Tte", null), new SqlParameter("p_Ty_Gia", null) };
            values[1].Direction = ParameterDirection.Output;
            values[1].SqlDbType = SqlDbType.NChar;
            values[1].Size = 1;
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.Decimal;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmTte_Exchange_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                num = (decimal) values[2].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return num;
        }

        public decimal ExchangeRate(object ps_Ma_Tte, ref bool pb_ExchangeType)
        {
            decimal num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Tte", ps_Ma_Tte), new SqlParameter("p_Loai_Tte", null), new SqlParameter("p_Ty_Gia", null) };
            values[1].Direction = ParameterDirection.Output;
            values[1].SqlDbType = SqlDbType.NChar;
            values[1].Size = 1;
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.Decimal;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmTte_Exchange_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                pb_ExchangeType = ((string) values[1].Value) == "0";
                num = (decimal) values[2].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return num;
        }

        public void GetBankAccount(object ps_MasterKey, ref object ps_Ten_Dvi_A, ref object ps_Tk_NH_A, ref object ps_Ten_NH_A, ref object ps_Ten_TP_A, ref object ps_Ten_Dvi_B, ref object ps_Tk_NH_B, ref object ps_Ten_NH_B, ref object ps_Ten_TP_B)
        {
            SqlParameter[] values = new SqlParameter[9];
            values[0] = new SqlParameter("p_Stt", ps_MasterKey);
            values[1] = new SqlParameter("p_Ten_Dvi_A", null);
            values[1].Direction = ParameterDirection.Output;
            values[1].SqlDbType = SqlDbType.NVarChar;
            values[1].Size = 0x80;
            values[2] = new SqlParameter("p_Tk_NH_A", null);
            values[2].Direction = ParameterDirection.Output;
            values[2].SqlDbType = SqlDbType.NVarChar;
            values[2].Size = 0x20;
            values[3] = new SqlParameter("p_Ten_NH_A", null);
            values[3].Direction = ParameterDirection.Output;
            values[3].SqlDbType = SqlDbType.NVarChar;
            values[3].Size = 0x80;
            values[4] = new SqlParameter("p_Ten_TP_A", null);
            values[4].Direction = ParameterDirection.Output;
            values[4].SqlDbType = SqlDbType.NVarChar;
            values[4].Size = 0x80;
            values[5] = new SqlParameter("p_Ten_Dvi_B", null);
            values[5].Direction = ParameterDirection.Output;
            values[5].SqlDbType = SqlDbType.NVarChar;
            values[5].Size = 0x80;
            values[6] = new SqlParameter("p_Tk_NH_B", null);
            values[6].Direction = ParameterDirection.Output;
            values[6].SqlDbType = SqlDbType.NVarChar;
            values[6].Size = 0x20;
            values[7] = new SqlParameter("p_Ten_NH_B", null);
            values[7].Direction = ParameterDirection.Output;
            values[7].SqlDbType = SqlDbType.NVarChar;
            values[7].Size = 0x80;
            values[8] = new SqlParameter("p_Ten_TP_B", null);
            values[8].Direction = ParameterDirection.Output;
            values[8].SqlDbType = SqlDbType.NVarChar;
            values[8].Size = 0x80;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtBN_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                ps_Ten_Dvi_A = values[1].Value;
                ps_Tk_NH_A = values[2].Value;
                ps_Ten_NH_A = values[3].Value;
                ps_Ten_TP_A = values[4].Value;
                ps_Ten_Dvi_B = values[5].Value;
                ps_Tk_NH_B = values[6].Value;
                ps_Ten_NH_B = values[7].Value;
                ps_Ten_TP_B = values[8].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

        public DataTable GetDetailHistoryTable(string ps_Ma_Nvu, object pi_HistoryID)
        {
            DataTable table2;
            string str = "";
            switch (ps_Ma_Nvu)
            {
                case "B":
                    str = "CtBH0_One_Log_Get";
                    break;

                case "D":
                    str = "CtDH0_One_Log_Get";
                    break;

                case "K":
                    str = "CtK0_One_Log_Get";
                    break;

                case "M":
                    str = "CtMH0_One_Log_Get";
                    break;

                case "N":
                    str = "CtNX0_One_Log_Get";
                    break;

                case "P":
                    str = "CtTP0_One_Log_Get";
                    break;

                case "Q":
                    str = "CtBG0_One_Log_Get";
                    break;

                case "S":
                    str = "CtSX0_One_Log_Get";
                    break;

                case "T":
                    str = "CtVAT0_One_Log_Get";
                    break;

                case "W":
                    str = "CtKho0_One_Log_Get";
                    break;

                case "X":
                    str = "CtKho0_One_Log_Get";
                    break;

                case "H":
                    str = "CtKho0_One_Log_Get";
                    break;

                case "G":
                    str = "CtKho0_One_Log_Get";
                    break;

                case "Y":
                    str = "CtKho0_One_Log_Get";
                    break;
                case "C":
                    str = "CtKho0_One_Log_Get";
                    break;
                case "L":
                    str = "CtKho0_One_Log_Get";
                    break;
                case "O":
                    str = "CtK0NB_One_Log_Get";
                    break;
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt_Log", pi_HistoryID) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable GetHistoryTable(object ps_InvoiceOrder)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Ct_Log_One_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable GetHistoryTable(string ps_Subsidiary, string ps_InvoiceCode, object pd_Ngay_Ct1, object pd_Ngay_Ct2)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ma_Ct", ps_InvoiceCode), new SqlParameter("p_Ngay_Ct1", pd_Ngay_Ct1), new SqlParameter("p_Ngay_Ct2", pd_Ngay_Ct2) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Ct_Log_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataRow GetInvoiceRow(string ps_InvoiceCode)
        {
            DataRow row;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Ct", ps_InvoiceCode) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmCt_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                row = dataTable.Rows[0];
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return row;
        }

        public DataTable GetInvoices(string ps_InvoiceCode)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Ct", ps_InvoiceCode) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmCt_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataRow GetMasterHistoryDataRow(string ps_Ma_Nvu, object pi_HistoryID)
        {
            DataRow row;
            string str = "";
            switch (ps_Ma_Nvu)
            {
                case "B":
                    str = "CtBH_One_Log_Get";
                    break;

                case "D":
                    str = "CtDH_One_Log_Get";
                    break;

                case "K":
                    str = "CtK_One_Log_Get";
                    break;

                case "M":
                    str = "CtMH_One_Log_Get";
                    break;

                case "N":
                    str = "CtNX_One_Log_Get";
                    break;

                case "P":
                    str = "CtTP_One_Log_Get";
                    break;

                case "Q":
                    str = "CtBG_One_Log_Get";
                    break;

                case "S":
                    str = "CtSX_One_Log_Get";
                    break;

                case "T":
                    str = "CtVAT_One_Log_Get";
                    break;

                case "W":
                    str = "CtKho_One_Log_Get";
                    break;

                case "X":
                    str = "CtKho_One_Log_Get";
                    break;

                case "H":
                    str = "CtKho_One_Log_Get";
                    break;
                
                case "G":
                    str = "CtKho_One_Log_Get";
                    break;

                case "Y":
                    str = "CtKho_One_Log_Get";
                    break;
                case "L":
                    str = "CtKho_One_Log_Get";
                    break;
                case "C":
                    str = "CtKho_One_Log_Get";
                    break;
                case "O":
                    str = "CtKNB_One_Log_Get";
                    break;
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt_Log", pi_HistoryID) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                row = dataTable.Rows[0];
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return row;
        }

        public DataTable GetMasterHistoryTable(string ps_Ma_Nvu, object ps_InvoiceOrder)
        {
            DataTable table2;
            string str = "";
            switch (ps_Ma_Nvu)
            {
                case "B":
                    str = "CtBH_Log_Get";
                    break;

                case "D":
                    str = "CtDH_Log_Get";
                    break;

                case "K":
                    str = "CtK_Log_Get";
                    break;

                case "M":
                    str = "CtMH_Log_Get";
                    break;

                case "N":
                    str = "CtNX_Log_Get";
                    break;

                case "P":
                    str = "CtTP_Log_Get";
                    break;

                case "Q":
                    str = "CtBG_Log_Get";
                    break;

                case "S":
                    str = "CtSX_Log_Get";
                    break;

                case "T":
                    str = "CtVAT_Log_Get";
                    break;

                case "W":
                    str = "CtKho_Log_Get";
                    break;
                
                case "X":
                    str = "CtKho_Log_Get";
                    break;

                case "H":
                    str = "CtKho_Log_Get";
                    break;
                
                case "G":
                    str = "CtKho_Log_Get";
                    break;

                case "Y":
                    str = "CtKho_Log_Get";
                    break;
                case "C":
                    str = "CtKho_Log_Get";
                    break;
                case "L":
                    str = "CtKho_Log_Get";
                    break;
                case "O":
                    str = "CtKNB_Log_Get";
                    break;
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable GetPaymentDetailTable(string ps_Subsidiary, object ps_InvoiceOrder, object ps_Ma_Bp, object ps_Ma_Hd, object ps_Ma_Dt, object ps_No_Co, object ps_Tk, object ps_Ma_Tte, object pd_Han_Tt, object pd_Ngay_Ct)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Ma_Bp", ps_Ma_Bp), new SqlParameter("p_Ma_Hd", ps_Ma_Hd), new SqlParameter("p_Ma_Dt", ps_Ma_Dt), new SqlParameter("p_No_Co", ps_No_Co), new SqlParameter("p_Tk", ps_Tk), new SqlParameter("p_Ma_Tte", ps_Ma_Tte), new SqlParameter("p_Han_Tt", pd_Han_Tt), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtCN_Detail_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable GetPaymentMasterTable(object ps_InvoiceOrder)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtCN_Master_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public int InvoiceStatus(string ps_Subsidiary, string ps_Ma_Nvu, string ps_UserName, object ps_InvoiceOrder)
        {
            int num;
            string str = "";
            string str2 = ps_Ma_Nvu;
            if (str2 != null)
            {
                if (!(str2 == "B"))
                {
                    if (str2 == "K")
                    {
                        str = "CheckInvoiceStatusKT";
                    }
                    else if (str2 == "M")
                    {
                        str = "CheckInvoiceStatusMH";
                    }
                    else if (str2 == "V")
                    {
                        str = "CheckInvoiceStatusNX";
                    }
                }
                else
                {
                    str = "CheckInvoiceStatusBH";
                }
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt", ps_InvoiceOrder), new SqlParameter("p_Check", null) };
            values[3].Direction = ParameterDirection.Output;
            values[3].SqlDbType = SqlDbType.Int;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                num = (int) values[3].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return num;
        }

        public void MakeAmountWarningMessage(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Tk, ref string ps_Ten_Tk, ref string ps_Ten_Tk_E, object ps_Ma_Dt, ref string ps_No_Co, ref string ps_Ten_Dt, ref string ps_Ten_Dt_E, string ps_SQLCmd, ref decimal pi_Du_No, ref decimal pi_Du_Co, ref decimal pi_Tien_Lmt)
        {
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Tk_Dt_Warning");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[13];
            values[0] = new SqlParameter("p_Ma_Dvcs", ps_Subsidiary);
            values[1] = new SqlParameter("p_Stt", ps_MasterKey);
            values[2] = new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct);
            values[3] = new SqlParameter("p_Tk", ps_Tk);
            values[4] = new SqlParameter("p_Ten_Tk", null);
            values[4].Direction = ParameterDirection.Output;
            values[4].Size = 0x80;
            values[4].SqlDbType = SqlDbType.NVarChar;
            values[5] = new SqlParameter("p_Ten_Tk_E", null);
            values[5].Direction = ParameterDirection.Output;
            values[5].Size = 0x80;
            values[5].SqlDbType = SqlDbType.NVarChar;
            values[6] = new SqlParameter("p_Ma_Dt", ps_Ma_Dt);
            values[7] = new SqlParameter("p_No_Co", null);
            values[7].Direction = ParameterDirection.Output;
            values[7].Size = 1;
            values[7].SqlDbType = SqlDbType.NVarChar;
            values[8] = new SqlParameter("p_Ten_Dt", null);
            values[8].Direction = ParameterDirection.Output;
            values[8].Size = 0x80;
            values[8].SqlDbType = SqlDbType.NVarChar;
            values[9] = new SqlParameter("p_Ten_Dt_E", null);
            values[9].Direction = ParameterDirection.Output;
            values[9].Size = 0x80;
            values[9].SqlDbType = SqlDbType.NVarChar;
            values[10] = new SqlParameter("p_Du_No", null);
            values[10].Direction = ParameterDirection.Output;
            values[10].SqlDbType = SqlDbType.Decimal;
            values[11] = new SqlParameter("p_Du_Co", null);
            values[11].Direction = ParameterDirection.Output;
            values[11].SqlDbType = SqlDbType.Decimal;
            values[12] = new SqlParameter("p_Tien_Lmt", null);
            values[12].Direction = ParameterDirection.Output;
            values[12].SqlDbType = SqlDbType.Decimal;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Tk_Dt_Warning";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                ps_Ten_Tk = (string) values[4].Value;
                ps_Ten_Tk_E = (string) values[5].Value;
                ps_No_Co = (string) values[7].Value;
                ps_Ten_Dt = (string) values[8].Value;
                ps_Ten_Dt_E = (string) values[9].Value;
                pi_Du_No = (decimal) values[10].Value;
                pi_Du_Co = (decimal) values[11].Value;
                pi_Tien_Lmt = (decimal) values[12].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Tk_Dt_Warning");
        }

        public void MakeLotQtyWarningMessage(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, ref string ps_Ten_Kho, ref string ps_Ten_Kho_E, object ps_Ma_Vt, ref string ps_Ten_Vt, ref string ps_Ten_Vt_E, ref string ps_Dvt, ref string ps_Dvt_E, object ps_Lo_Hang, string ps_SQLCmd, ref decimal pi_Ton_Kho)
        {
            SSDataAccess.RunSQLCommand("DROP PROCEDURE VT_KhoKT_Lo_Hang_Warning");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[13];
            values[0] = new SqlParameter("p_Ma_Dvcs", ps_Subsidiary);
            values[1] = new SqlParameter("p_Stt", ps_MasterKey);
            values[2] = new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct);
            values[3] = new SqlParameter("p_Ma_Kho", ps_Ma_Kho);
            values[4] = new SqlParameter("p_Ten_Kho", null);
            values[4].Direction = ParameterDirection.Output;
            values[4].Size = 0x80;
            values[4].SqlDbType = SqlDbType.NVarChar;
            values[5] = new SqlParameter("p_Ten_Kho_E", null);
            values[5].Direction = ParameterDirection.Output;
            values[5].Size = 0x80;
            values[5].SqlDbType = SqlDbType.NVarChar;
            values[6] = new SqlParameter("p_Ma_Vt", ps_Ma_Vt);
            values[7] = new SqlParameter("p_Ten_Vt", null);
            values[7].Direction = ParameterDirection.Output;
            values[7].Size = 0x80;
            values[7].SqlDbType = SqlDbType.NVarChar;
            values[8] = new SqlParameter("p_Ten_Vt_E", null);
            values[8].Direction = ParameterDirection.Output;
            values[8].Size = 0x80;
            values[8].SqlDbType = SqlDbType.NVarChar;
            values[9] = new SqlParameter("p_Dvt", null);
            values[9].Direction = ParameterDirection.Output;
            values[9].Size = 20;
            values[9].SqlDbType = SqlDbType.NVarChar;
            values[10] = new SqlParameter("p_Dvt_E", null);
            values[10].Direction = ParameterDirection.Output;
            values[10].Size = 20;
            values[10].SqlDbType = SqlDbType.NVarChar;
            values[11] = new SqlParameter("p_Lo_Hang", ps_Lo_Hang);
            values[12] = new SqlParameter("p_Ton_Kho", null);
            values[12].Direction = ParameterDirection.Output;
            values[12].SqlDbType = SqlDbType.Decimal;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "VT_KhoKT_Lo_Hang_Warning";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                ps_Ten_Kho = (string) values[4].Value;
                ps_Ten_Kho_E = (string) values[5].Value;
                ps_Ten_Vt = (string) values[7].Value;
                ps_Ten_Vt_E = (string) values[8].Value;
                ps_Dvt = (string) values[9].Value;
                ps_Dvt_E = (string) values[10].Value;
                pi_Ton_Kho = (decimal) values[12].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            SSDataAccess.RunSQLCommand("DROP PROCEDURE VT_KhoKT_Lo_Hang_Warning");
        }

        public DataTable MakeLotQuantity(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, object ps_Ma_Vt, object ps_Lo_Hang, string ps_SQLCmd, int pi_Max_Rows)
        {
            DataTable table2;
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt), new SqlParameter("p_Lo_Hang", ps_Lo_Hang), new SqlParameter("p_Max_Rows", pi_Max_Rows) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Lo_Hang_Xuat_Kho_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable MakeOutLotQuantity(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, object ps_Ma_Vt, object ps_Lo_Hang, string ps_SQLCmd, int pi_Max_Rows)
        {
            DataTable table2;
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt), new SqlParameter("p_Lo_Hang", ps_Lo_Hang), new SqlParameter("p_Max_Rows", pi_Max_Rows) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Lo_Hang_Xuat_Kho_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public void MakeQtyWarningMessage(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, ref string ps_Ten_Kho, ref string ps_Ten_Kho_E, object ps_Ma_Vt, ref string ps_Ten_Vt, ref string ps_Ten_Vt_E, ref string ps_Dvt, ref string ps_Dvt_E, string ps_SQLCmd, ref decimal pi_Ton_Kho, ref decimal pi_SL_Ton_Min, ref decimal pi_SL_Ton_Max)
        {
            SSDataAccess.RunSQLCommand("DROP PROCEDURE VT_KhoKT_Warning");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[14];
            values[0] = new SqlParameter("p_Ma_Dvcs", ps_Subsidiary);
            values[1] = new SqlParameter("p_Stt", ps_MasterKey);
            values[2] = new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct);
            values[3] = new SqlParameter("p_Ma_Kho", ps_Ma_Kho);
            values[4] = new SqlParameter("p_Ten_Kho", null);
            values[4].Direction = ParameterDirection.Output;
            values[4].Size = 0x80;
            values[4].SqlDbType = SqlDbType.NVarChar;
            values[5] = new SqlParameter("p_Ten_Kho_E", null);
            values[5].Direction = ParameterDirection.Output;
            values[5].Size = 0x80;
            values[5].SqlDbType = SqlDbType.NVarChar;
            values[6] = new SqlParameter("p_Ma_Vt", ps_Ma_Vt);
            values[7] = new SqlParameter("p_Ten_Vt", null);
            values[7].Direction = ParameterDirection.Output;
            values[7].Size = 0x80;
            values[7].SqlDbType = SqlDbType.NVarChar;
            values[8] = new SqlParameter("p_Ten_Vt_E", null);
            values[8].Direction = ParameterDirection.Output;
            values[8].Size = 0x80;
            values[8].SqlDbType = SqlDbType.NVarChar;
            values[9] = new SqlParameter("p_Dvt", null);
            values[9].Direction = ParameterDirection.Output;
            values[9].Size = 20;
            values[9].SqlDbType = SqlDbType.NVarChar;
            values[10] = new SqlParameter("p_Dvt_E", null);
            values[10].Direction = ParameterDirection.Output;
            values[10].Size = 20;
            values[10].SqlDbType = SqlDbType.NVarChar;
            values[11] = new SqlParameter("p_Ton_Kho", null);
            values[11].Direction = ParameterDirection.Output;
            values[11].SqlDbType = SqlDbType.Decimal;
            values[12] = new SqlParameter("p_SL_Ton_Min", null);
            values[12].Direction = ParameterDirection.Output;
            values[12].SqlDbType = SqlDbType.Decimal;
            values[13] = new SqlParameter("p_SL_Ton_Max", null);
            values[13].Direction = ParameterDirection.Output;
            values[13].SqlDbType = SqlDbType.Decimal;
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "VT_KhoKT_Warning";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
                ps_Ten_Kho = (string) values[4].Value;
                ps_Ten_Kho_E = (string) values[5].Value;
                ps_Ten_Vt = (string) values[7].Value;
                ps_Ten_Vt_E = (string) values[8].Value;
                ps_Dvt = (string) values[9].Value;
                ps_Dvt_E = (string) values[10].Value;
                pi_Ton_Kho = (decimal) values[11].Value;
                pi_SL_Ton_Min = (decimal) values[12].Value;
                pi_SL_Ton_Max = (decimal) values[13].Value;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            SSDataAccess.RunSQLCommand("DROP PROCEDURE VT_KhoKT_Warning");
        }

        public DataTable MakeStockLotQuantity(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, object ps_Ma_Vt, string ps_SQLCmd)
        {
            DataTable table2;
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Vt", ps_Ma_Vt) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Lo_Hang_Xuat_Kho_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable MakeStockLotQuantity(string ps_Subsidiary, object ps_MasterKey, object pd_Ngay_Ct, object ps_Ma_Kho, object ps_Ma_Ke, object ps_Ma_Vt, object ps_Lo_Hang, string ps_SQLCmd, int pi_Max_Rows)
        {
            DataTable table2;
            SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
            SSDataAccess.RunSQLCommand(ps_SQLCmd);
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ngay_Ct", pd_Ngay_Ct), new SqlParameter("p_Ma_Kho", ps_Ma_Kho), new SqlParameter("p_Ma_Ke", ps_Ma_Ke), new SqlParameter("p_Ma_Vt", ps_Ma_Vt), new SqlParameter("p_Lo_Hang", ps_Lo_Hang), new SqlParameter("p_Max_Rows", pi_Max_Rows) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "Lo_Hang_Xuat_Kho_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                SSDataAccess.RunSQLCommand("DROP PROCEDURE Lo_Hang_Xuat_Kho_Get");
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public DataTable RefTable_Get(object ps_MasterKey)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            DataTable dataTable = new DataTable("VBSP");
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "RefTable_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);                
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
            return table2;
        }

        public void ResetInvoiceNumber(string ps_StoredProcedure, string ps_Subsidiary, string ps_InvoiceCode, object pd_Ngay_Ct1, object pd_Ngay_Ct2, object ps_So_Ct0, object pi_So_Ct1)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Ma_Dvcs", ps_Subsidiary), new SqlParameter("p_Ma_Ct", ps_InvoiceCode), new SqlParameter("p_Ngay_Ct1", pd_Ngay_Ct1), new SqlParameter("p_Ngay_Ct2", pd_Ngay_Ct2), new SqlParameter("p_So_Ct0", ps_So_Ct0), new SqlParameter("p_So_Ct1", pi_So_Ct1) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = ps_StoredProcedure;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

        public void Restore(string ps_Ma_Nvu, string ps_UserName, object ps_InvoiceOrder, object pi_HistoryID)
        {
            string str = "";
            switch (ps_Ma_Nvu)
            {
                case "B":
                    str = "CtBH_Restore";
                    break;

                case "D":
                    str = "CtDH_Restore";
                    break;

                case "K":
                    str = "CtK_Restore";
                    break;

                case "M":
                    str = "CtMH_Restore";
                    break;

                case "N":
                    str = "CtNX_Restore";
                    break;

                case "P":
                    str = "CtTP_Restore";
                    break;

                case "Q":
                    str = "CtBG_Restore";
                    break;

                case "S":
                    str = "CtSX_Restore";
                    break;

                case "T":
                    str = "CtVAT_Restore";
                    break;

                case "W":
                    str = "CtKho_Restore";
                    break;

                case "Y":
                    str = "CtKho_Restore";
                    break;

                case "O":
                    str = "CtKNB_Restore";
                    break;
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_UserName", ps_UserName), new SqlParameter("p_Stt_Log", pi_HistoryID), new SqlParameter("p_Stt", ps_InvoiceOrder) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression: ", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

        public bool Save(string ps_Ma_Nvu, DataRow po_MasterDataRow, DataTable po_DetailTable)
        {
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlTransaction transaction = SSConnection.BeginTransaction();
            this.DeletePayment(SSConnection, transaction, po_MasterDataRow["Stt"], po_MasterDataRow["Ma_Bp"], po_MasterDataRow["Ma_Hd"], po_MasterDataRow["Ma_Dt"], po_MasterDataRow["No_Co"], po_MasterDataRow["Tk"], po_MasterDataRow["Ma_Tte"], po_MasterDataRow["Han_Tt"]);
            foreach (DataRow row in po_DetailTable.Rows)
            {
                row.EndEdit();
                if ((row.RowState != DataRowState.Deleted) && (((decimal) row["Tien_Nt"]) != 0M))
                {
                    this.SavePayment(SSConnection, transaction, row["Stt"], po_MasterDataRow["Ma_Bp"], po_MasterDataRow["Ma_Hd"], po_MasterDataRow["Ma_Dt"], po_MasterDataRow["No_Co"], po_MasterDataRow["Tk"], po_MasterDataRow["Ma_Tte"], row["Tien_Nt"], row["Han_Tt"], po_MasterDataRow["Han_Tt"], po_MasterDataRow["Stt"]);
                }
            }
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", po_MasterDataRow["Stt"]) };
            string str = "";
            string str2 = ps_Ma_Nvu;
            if (str2 != null)
            {
                if (!(str2 == "B"))
                {
                    if (str2 == "K")
                    {
                        str = "CtKT_SoCaiKT_Save";
                    }
                    else if (str2 == "M")
                    {
                        str = "CtMH_SoCaiKT_Save";
                    }
                    else if (str2 == "V")
                    {
                        str = "CtNX_SoCaiKT_Save";
                    }
                }
                else
                {
                    str = "CtBH_SoCaiKT_Save";
                }
            }
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = str;
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Transaction = transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            transaction.Commit();
            SSDataAccess.CloseConnection(SSConnection);
            return true;
        }

        public void SaveBankAccount(object ps_MasterKey, object ps_Ten_Dvi_A, object ps_Tk_NH_A, object ps_Ten_NH_A, object ps_Ten_TP_A, object ps_Ten_Dvi_B, object ps_Tk_NH_B, object ps_Ten_NH_B, object ps_Ten_TP_B)
        {
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", ps_MasterKey), new SqlParameter("p_Ten_Dvi_A", ps_Ten_Dvi_A), new SqlParameter("p_Tk_NH_A", ps_Tk_NH_A), new SqlParameter("p_Ten_NH_A", ps_Ten_NH_A), new SqlParameter("p_Ten_TP_A", ps_Ten_TP_A), new SqlParameter("p_Ten_Dvi_B", ps_Ten_Dvi_B), new SqlParameter("p_Tk_NH_B", ps_Tk_NH_B), new SqlParameter("p_Ten_NH_B", ps_Ten_NH_B), new SqlParameter("p_Ten_TP_B", ps_Ten_TP_B) };
            SqlConnection SSConnection = SSDataAccess.SSConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtBN_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = SSConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();                
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); 
                throw new NotSupportedException("Invalid expression", exception);
            }
            finally
            {
                SSDataAccess.Close(SSConnection);
            }
        }

        public bool SavePayment(SqlConnection po_Connection, SqlTransaction po_Transaction, object ps_InvoiceOrder, object ps_Ma_Bp, object ps_Ma_Hd, object ps_Ma_Dt, object ps_No_Co, object ps_Tk, object ps_Ma_Tte, object pi_Tien_Nt, object pd_Han_Tt0, object pd_Han_Tt1, object ps_DOrder)
        {
            bool flag;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_S_Order", ps_InvoiceOrder), new SqlParameter("p_Ma_Bp", ps_Ma_Bp), new SqlParameter("p_Ma_Hd", ps_Ma_Hd), new SqlParameter("p_Ma_Dt", ps_Ma_Dt), new SqlParameter("p_No_Co", ps_No_Co), new SqlParameter("p_Tk", ps_Tk), new SqlParameter("p_Ma_Tte", ps_Ma_Tte), new SqlParameter("p_Tien_Nt", pi_Tien_Nt), new SqlParameter("p_Han_Tt0", pd_Han_Tt0), new SqlParameter("p_Han_Tt1", pd_Han_Tt1), new SqlParameter("p_D_Order", ps_DOrder) };
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "CtCN_Detail_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = po_Connection;
                command.Transaction = po_Transaction;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                flag = true;
            }
            catch (Exception exception)
            {
                log.ErrorException(string.Empty, exception); throw new NotSupportedException("Invalid expression", exception);
            }
            return flag;
        }
    }
}

